﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OOLib
{
   /// <summary>
   /// A TextCursor is a TextRange which can be moved within a Text object.
   /// </summary>
   public class TextCursor : TextRange
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public TextCursor() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public TextCursor(object comObject) :
         base(comObject)
      { }

      #endregion

      #region XTextCursor

      /// <summary>
      /// Sets the end of the position to the start.
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public void CollapseToStart()
      {
         CheckDisposed();
         InvokeMethod("collapseToStart");
      }

      /// <summary>
      /// Sets the start of the position to the end.
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public void CollapseToEnd()
      {
         CheckDisposed();
         InvokeMethod("collapseToEnd");
      }

      /// <summary>
      /// Get if the start and end positions are the same.
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public bool IsCollapsed
      {
         get 
         {
            CheckDisposed();
            return (bool)InvokeMethod("isCollapsed"); 
         }
      }

      /// <summary>
      /// Moves the cursor the specified number of characters to the left.
      /// </summary>
      /// <param name="count">The number of characters to move.</param>
      /// <param name="expand">Specifies if the current selection of the cursor should be expanded or not.</param>
      /// <returns>
      /// true if the command was successfully completed. false otherwise. 
      /// Note: Even if the command was not completed successfully it may be completed partially. E.g. if it was required 
      /// to move 5 characters but it is only possible to move 3 false will be returned and the cursor moves only those 3 characters.
      /// </returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public bool GoLeft(int count, bool expand)
      {
         CheckDisposed();
         return (bool)InvokeMethod("goLeft", count, expand);
      }

      /// <summary>
      /// Moves the cursor the specified number of characters to the right.
      /// </summary>
      /// <param name="count">The number of characters to move.</param>
      /// <param name="expand">Specifies if the current selection of the cursor should be expanded or not.</param>
      /// <returns>
      /// true if the command was successfully completed. false otherwise.
      /// Note: Even if the command was not completed successfully it may be completed partially. E.g. if it was required 
      /// to move 5 characters but it is only possible to move 3 false will be returned and the cursor moves only those 3 characters.
      /// </returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public bool GoRight(int count, bool expand)
      {
         CheckDisposed();
         return (bool)InvokeMethod("goRight", count, expand);
      }

      /// <summary>
      /// Moves the cursor to the start of the text.
      /// </summary>
      /// <param name="expand">Specifies if the current selection of the cursor should be expanded or not.</param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void GotoStart(bool expand)
      {
         CheckDisposed();
         InvokeMethod("gotoStart", expand);
      }

      /// <summary>
      /// Moves the cursor to the end of the text.
      /// </summary>
      /// <param name="expand">Specifies if the current selection of the cursor should be expanded or not.</param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void GotoEnd(bool expand)
      {
         CheckDisposed();
         InvokeMethod("gotoEnd", expand);
      }

      /// <summary>
      /// Moves or expands the cursor to a specified TextRange.
      /// </summary>
      /// <param name="range">TextRange</param>
      /// <param name="expand">Specifies if the current selection of the cursor should be expanded or not.</param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void GotoRange(TextRange range, bool expand)
      {
         CheckDisposed();
         InvokeMethod("gotoRange", range.ComObj, expand);
      }

      #endregion
   }
}
